package ks.managers.user;

import java.util.Collection;
import java.util.Hashtable;

/**
 * Manages all known users.
 * 
 * @author George Heineman
 * @author Christopher Page
 */
public class UserManager {

	/**
	 * Hashtable of known users.
	 * 
	 * @see #getUser(String)
	 * @see #getUserList()
	 * @see #addUser(User)
	 * @see #removeUser(User)
	 */
	protected Hashtable<String, User> knownUsers = new Hashtable<String, User>();
	
	
	
	
	
	/**
	 * Protect access to constructor.
	 */
	public UserManager() {}
	
	/**
	 * Retrieve individual user by name from the store of users.
	 * 
	 * @param loggingInUser The username of the user.
	 * @return A User corresponding to the given username.
	 */
	public User getUser(String loggingInUser) {
		return knownUsers.get(loggingInUser);
	}
	
	/**
	 * Retrieve all known users and return a collection of them.
	 * 
	 * @return A Collection of User class instances.
	 */
	public Collection<User> getUserList() {
		return knownUsers.values();
	}
	
	/**
	 * Add user to the store of users.
	 * 
	 * @param u The User to add to the store of users.
	 * @return true on success.
	 */
	public boolean addUser (User u) {
		knownUsers.put(u.name, u);
		
		return true;
	}

	/**
	 * Remove user from the store of users.
	 * 
	 * @param u The User to remove from the store of users.
	 * @return true on success.
	 */
	public boolean removeUser (User u) {
		knownUsers.remove(u.name);
		
		return true;
	}
	
	/**
	 * Remove all users from the store of users.
	 * 
	 * @return true on success.
	 */
	public boolean removeAllUsers () {
		knownUsers = new Hashtable<String, User>();
		
		return true;
	}
}
